package edu.lingnan.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.lingnan.dto.FeedbackReq;
import edu.lingnan.entity.Feedback;
import edu.lingnan.service.FeedbackService;
import edu.lingnan.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName FeedbackController
 * @Description TODO
 * @Author kang
 * @Date 2022/9/16 下午 9:10
 * @Version 1.0
 */
@RestController
@RequestMapping("/feedback")
@Api(tags = "反馈控制器")
public class FeedbackController {

    @Resource
    private FeedbackService feedbackService;

    @ApiOperation("获取反馈信息列表")
    @GetMapping
    public Result list(@RequestParam Integer currentPage, @RequestParam Integer size) {
        Page<Feedback> page = feedbackService.page(
                new Page<Feedback>(currentPage, size),
                new LambdaQueryWrapper<Feedback>().orderByDesc(Feedback::getId)
        );
        return new Result(true, page, "操作成功");
    }

    //@PutMapping("/{id}")
    //@ApiOperation("处理反馈")
    //public Result deal(@PathVariable @ApiParam("需要处理返回的id") Long id){
    //    Feedback feedback = new Feedback();
    //    feedback.setId(id);
    //    feedback.setStatus(1);
    //    feedbackService.updateById(feedback);
    //    return new Result(true, null, "操作成功");
    //}

    @PostMapping
    @ApiOperation("新增反馈")
    public Result add(@RequestBody Feedback feedback) {
        feedback.setFeedbackTime(LocalDateTime.now());
        feedbackService.save(feedback);
        return new Result(true, null, "反馈成功");
    }

}
